package com.lyb.spzx.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyb.spzx.manager.mapper.CategoryBrandMapper;
import com.lyb.spzx.manager.service.CategoryBrandService;
import com.lyb.spzx.model.dto.product.CategoryBrandDto;
import com.lyb.spzx.model.entity.product.Brand;
import com.lyb.spzx.model.entity.product.CategoryBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CategoryBrandServiceImpl implements CategoryBrandService {

    @Autowired
    CategoryBrandMapper categoryBrandMapper;
    @Override
    public PageInfo<CategoryBrand> findAllDataByPage(Integer pageNum,
                                                     Integer pageSize,
                                                     CategoryBrandDto categoryBrandDto) {

        PageHelper.startPage(pageNum,pageSize);
        List<CategoryBrand> categoryBrands = categoryBrandMapper.findAllDataByPage(categoryBrandDto);
        return new PageInfo<>(categoryBrands);
    }

    @Override
    public void saveData(CategoryBrand categoryBrand) {
        categoryBrandMapper.saveData(categoryBrand);
    }

    @Override
    public void updateData(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateData(categoryBrand);
    }

    @Override
    public void deleteDataById(Long id) {
        categoryBrandMapper.deleteDataById(id);
    }

    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {
        List<Brand> brandList = categoryBrandMapper.findBrandByCategoryId(categoryId);
        return brandList;
    }
}
